<template>
  <div class="boxContent">
    <div class="appBox">
      <div class="searchList">
        <el-form :model="state.params"
                 ref="FormInstance "
                 class="boxFrom">
          <div class="searchBox">
            <template v-for="(item, index) in state.totalInputColumns"
                      :key="index">
              <el-form-item v-if="item.type == 'input'">
                <el-input clearable
                          v-model="state.params[item.key]"
                          :placeholder="item.label"></el-input>
              </el-form-item>
              <el-form-item v-if="item.type == 'select'">
                <el-select v-model="state.params[item.key]"
                           :placeholder="item.label"
                           clearable
                           v-if="item.key == 'sectorId'">
                  <el-option v-for="i in state.optionsPre"
                             :key="i"
                             :label="i.dictValue"
                             :value="i.id"></el-option>
                </el-select>
                <el-select v-model="state.params[item.key]"
                           :placeholder="item.label"
                           clearable
                           v-if="item.key == 'payType'">
                  <el-option value="qrcode"
                             label="扫码支付"></el-option>
                  <el-option value="offline"
                             label="线下支付"></el-option>
                </el-select>
                <el-select v-model="state.params[item.key]"
                           :placeholder="item.label"
                           clearable
                           v-if="item.key == 'status' && state.params.payType == 'qrcode'">
                  <el-option value="0"
                             label="待发起支付" />
                  <el-option value="1"
                             label="支付中" />
                  <el-option value="2"
                             label="已支付" />
                  <el-option value="3"
                             label="已退款" />
                  <el-option value="-1"
                             label="已取消" />
                </el-select>
                <el-select v-model="state.params[item.key]"
                           :placeholder="item.label"
                           clearable
                           v-if="item.key == 'status' && state.params.payType == 'offline'">
                  <el-option value="0"
                             label="待上传凭证" />
                  <el-option value="1"
                             label="待审核" />
                  <el-option value="2"
                             label="已入账" />
                  <el-option value="3"
                             label="已退款" />
                  <el-option value="-1"
                             label="已取消" />
                </el-select>

              </el-form-item>
              <el-form-item v-if="item.type == 'time'">
                <el-date-picker v-if="item.key == 'timexx'"
                                v-model="state.timexx"
                                type="daterange"
                                range-separator="至"
                                start-placeholder="开始时间"
                                value-format="YYYY-MM-DD"
                                end-placeholder="结束时间" />
              </el-form-item>
            </template>
          </div>

          <el-form-item class="btns">
            <el-button v-preventReClick
                       type="primary"
                       @click="methods.handleAction('export')"
                       v-permission="1150">导出</el-button>
            <el-button v-preventReClick
                       type="primary"
                       plain
                       @click="methods.handleAction('query')">搜索</el-button>
            <el-button v-preventReClick
                       @click="methods.handleAction('reset')">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="tabaleBox">
        <el-table border
                  v-loading="state.loading"
                  :data="state.tableData"
                  style="width: 100%"
                  :header-cell-style="{ color: '#000' }">
          <el-table-column prop="name"
                           label="昵称/姓名"
                           show-overflow-tooltip
                           align="center"
                           width="120" />
          <el-table-column prop="phone"
                           label="联系电话"
                           show-overflow-tooltip
                           align="center"
                           width="120">
          </el-table-column>
          <el-table-column prop="companyname"
                           label="派遣企业"
                           show-overflow-tooltip
                           align="left" />
          <el-table-column prop="type"
                           label="用户状态"
                           show-overflow-tooltip
                           align="center"
                           width="120" />
          <el-table-column prop="inducationBonus"
                           label="入职奖励（合计)"
                           show-overflow-tooltip
                           width="130"
                           align="center" />
          <el-table-column prop="signBonus"
                           label="签到绩效奖励（合计)"
                           show-overflow-tooltip
                           align="center"
                           width="160">
          </el-table-column>
          <el-table-column prop="useAmount"
                           label="当前可用余额"
                           show-overflow-tooltip
                           width="120"
                           align="center">

          </el-table-column>

          <el-table-column prop="btns"
                           label="操作"
                           show-overflow-tooltip
                           align="center"
                           width="100"
                           fixed="right">
            <template #default="scope">
              <div class=" btnsDatil">
                <div class=""
                     v-permission="1151"
                     @click="methods.handleAction('edit', scope.row)">查看详情</div>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="pagination">
        <el-pagination background
                       v-model:current-page="state.params.pageNum"
                       v-model:page-size="state.params.pageSize"
                       :page-sizes="[10, 20, 30, 50]"
                       layout="total, sizes, prev, pager, next, jumper"
                       :total="state.totalSize"
                       @size-change="methods.handleSizeChange"
                       @current-change="methods.handleCurrentChange" />
      </div>

    </div>
  </div>
</template>

<script setup>
import { onMounted, reactive, getCurrentInstance } from "vue";
import { ElMessage, ElLoading, ElMessageBox } from "element-plus";
import { useRouter } from "vue-router";
const router = useRouter();
const app = getCurrentInstance()?.proxy;
const initState = () => {
  return {

    loading: false,
    totalSize: 0,
    tableData: [],
    params: {
      pageNum: 1,
      pageSize: 10,
      // cid: JSON.parse(localStorage.getItem('userInfor')).cid,
      // account: JSON.parse(localStorage.getItem('userInfor')).account,
    },
    totalInputColumns: [
      { key: "namephone", label: "填写昵称/姓名/联系电话", type: "input" },
      { key: "cname", label: "企业名称", type: "input" },
    ],
  };
};
const state = reactive(initState());
onMounted(() => {
  state.optionsPre = JSON.parse(localStorage.getItem("profession"));
  methods.getDataList();
});
const methods = {

  handleAction (type, data, status) {
    switch (type) {
      case "export": //导出
        app.$http
          .get(
            `usermoney/queryListExport?namephone=${state.params.namephone || ''}&cname=${state.params.cname || ''}`,
            { responseType: "arraybuffer" }
          )
          .then((res) => {
            if (res) {
              app.$parse.downloadExcel(res, '资金统计数据')
            }
          });
        break;
      case "query": //查询
        methods.getDataList();
        break;
      case "reset": // 重置
        state.params = initState().params;
        state.timexx = []
        break;
      case "return": //拒绝 
        state.status = status
        if (data !== 'x') {
          state.drawerData = JSON.parse(JSON.stringify(data))
        }
        state.inputPass = ''
        state.dialogVisible = true
        break;
      case "edit": // 编辑
        app.$router.push('/balance/capitalDetails?id=' + data.uid)
        break;
      case "delete": // 删除
        ElMessageBox.confirm("请确认是否删除该招聘企业?", "删除招聘企业", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            app.$http.get("/company/deleteById?id=" + data.id).then((res) => {
              methods.getDataList();
              ElMessage({
                type: "success",
                message: "已删除",
              });
            });
          })
          .catch(() => {
            methods.getDataList();
            ElMessage({
              type: "info",
              message: "已取消",
            });
          });

        break;
    }
  },
  getDataList () {
    state.loading = true
    app.$get("/usermoney/queryList", state.params).then((res) => {
      state.tableData = res.data.data;
      state.totalSize = res.data.total;
      state.loading = false
    }).catch(() => {
      state.loading = false
    })
  },
  //分页变化
  handleSizeChange () {
    state.params.pageNum = 1;
    methods.getDataList();
  },
  //表格翻页
  handleCurrentChange () {
    methods.getDataList();
  },
};
</script>

<style lang="scss" scoped>
.appBox {
  background: #fff;
  border-radius: 5px;
  padding: 20px;
  height: calc(100% - 20px);
  width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  ::v-deep(.el-drawer__title) {
    color: rgba(0, 121, 254, 1);
    font-size: 18px;
    font-family: SourceHanSansSC-bold;
    font-weight: bold;
  }
  .drawerConcent {
    .title {
      color: rgb(16, 16, 16);
      font-size: 16px;
      text-align: left;
      font-family: SourceHanSansSC-regular;
    }
    .flex_sb {
      align-items: center;
      flex-wrap: wrap;
      .inputShow {
        margin-top: 16px;
        width: 48%;
        min-width: 260px;
      }
    }
  }
  .tabaleBox {
    overflow: hidden;
    flex: 1;
  }
  .btnsDatil {
    color: #0079fe;
    cursor: pointer;
    align-items: center;
  }
  .pagination {
    margin-top: 20px;
    height: 50px;
    display: flex;
    justify-content: flex-end;
  }
  ::v-deep(.el-dialog__body) {
    max-height: 380px;
  }
  .imgs {
    flex-wrap: wrap;
    .forbox {
      height: 150px;
      margin: 10px 0 0 10px;
    }
    .imgBox {
      height: 100%;
      width: auto;
    }
    .videoBox {
      width: auto;
      height: 100%;
    }
  }
}
</style>
